﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.InventoryUI {
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.event.*;
    import org.aswing.border.*;
    import Display.aswingui.*;

    public class RemoveItemDialogView extends GenericDialogView {

        public static const DIALOG_TEXT_WIDTH:int = 350;
        public static const COUNT_PANE_SIZE:int = 20;
        public static const OVERLAP_AMOUNT:int = 22;

        protected var m_itemName:String;
        protected var m_countPane:JPanel;
        protected var m_itemCount:int = 1;
        protected var m_textAreaInnerPane:JPanel;
        protected var m_textAP:Component;
        protected var m_overlapPane:JPanel;
        protected var m_bottomPane:JPanel;
        protected var m_rightBtn:JButton;
        protected var m_leftBtn:JButton;

        public function RemoveItemDialogView(_arg1:Dictionary, _arg2:String, _arg3:String="", _arg4:String="", _arg5:Function=null, _arg6:Function=null){
            this.m_itemName = _arg2;
            super(_arg1, _arg3, _arg4, TYPE_REMOVECANCEL, _arg5, "", 0, "", _arg6);
        }
        override protected function createTitlePanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            m_titleFontSize = TextFieldUtil.getLocaleFontSize(30, 20, null);
            var _local2:AssetPane = ASwingHelper.makeMultilineText(m_titleString, DIALOG_TEXT_WIDTH, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, 18, EmbeddedArt.blueTextColor);
            _local1.append(_local2);
            ASwingHelper.setEasyBorder(_local1, 60, 10, 0, 10);
            return (_local1);
        }
        override protected function createInteriorHolder():JPanel{
            var _local2:JPanel;
            var _local1:JPanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, -10, AsWingConstants.CENTER));
            _local2 = createHeaderPanel();
            ASwingHelper.prepare(_local2);
            textArea = this.createTextArea();
            ASwingHelper.prepare(textArea);
            _local1.setBorder(new EmptyBorder(null, new Insets(0, 0, 0, 0)));
            _local1.append(_local2);
            _local1.append(ASwingHelper.verticalStrut(20));
            _local1.append(textArea);
            _local1.append(ASwingHelper.verticalStrut(BUTTON_MARGIN));
            var _local3:JPanel = createButtonPanel();
            _local1.append(_local3);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        override protected function createTextArea():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 10);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER, 10);
            ASwingHelper.setEasyBorder(_local2, 10);
            var _local3:JPanel = this.createCenterArea();
            _local2.append(_local3);
            this.m_textAP = this.createTextComponent(DIALOG_TEXT_WIDTH);
            this.m_textAreaInnerPane = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.m_textAreaInnerPane.append(this.m_textAP);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local4.append(this.m_textAreaInnerPane);
            ASwingHelper.prepare(_local4);
            _local2.append(_local4);
            ASwingHelper.prepare(_local2);
            _local1.append(_local2);
            return (_local1);
        }
        override protected function createTextComponent(_arg1:Number):Component{
            var _local2:Component = ASwingHelper.makeMultilineText(m_message, _arg1, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, 22, EmbeddedArt.brownTextColor);
            var _local3:Container = ASwingHelper.makeSoftBoxJPanelVertical();
            _local3.append(_local2);
            _local3.append(ASwingHelper.verticalStrut(10));
            _local3.append(ASwingHelper.verticalStrut(10));
            return (_local3);
        }
        protected function createCenterArea():JPanel{
            var _local1:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER, 10);
            var _local2:DisplayObject = (new (m_assetDict["btn_minus_up"])() as DisplayObject);
            var _local3:DisplayObject = (new (m_assetDict["btn_minus_over"])() as DisplayObject);
            var _local4:DisplayObject = (new (m_assetDict["btn_minus_down"])() as DisplayObject);
            var _local5:DisplayObject = (new (m_assetDict["btn_plus_up"])() as DisplayObject);
            var _local6:DisplayObject = (new (m_assetDict["btn_plus_over"])() as DisplayObject);
            var _local7:DisplayObject = (new (m_assetDict["btn_plus_down"])() as DisplayObject);
            this.m_leftBtn = new JButton();
            this.m_leftBtn.wrapSimpleButton(new SimpleButton(_local2, _local3, _local4, _local2));
            if (Global.player.inventory.getItemCountByName(this.m_itemName) <= 1){
                this.m_leftBtn.setEnabled(false);
            };
            ASwingHelper.setEasyBorder(this.m_leftBtn, 0, 0, 20, 3);
            this.m_rightBtn = new JButton();
            this.m_rightBtn.wrapSimpleButton(new SimpleButton(_local5, _local6, _local7, _local5));
            if (Global.player.inventory.getItemCountByName(this.m_itemName) <= 1){
                this.m_rightBtn.setEnabled(false);
            };
            ASwingHelper.setEasyBorder(this.m_rightBtn, 0, 3, 20);
            this.m_rightBtn.addActionListener(this.incrementCount, 0, true);
            this.m_leftBtn.addActionListener(this.decrementCount, 0, true);
            this.m_overlapPane = this.createCell();
            _local1.appendAll(this.m_leftBtn, this.m_overlapPane, this.m_rightBtn);
            return (_local1);
        }
        protected function incrementCount(_arg1:AWEvent):void{
            if (this.m_itemCount < Global.player.inventory.getItemCountByName(this.m_itemName)){
                this.m_itemCount = (this.m_itemCount + 1);
            } else {
                if (this.m_itemCount == Global.player.inventory.getItemCountByName(this.m_itemName)){
                    this.m_itemCount = 1;
                };
            };
            this.m_bottomPane.remove(this.m_countPane);
            this.m_countPane = this.makeCountPane();
            this.m_bottomPane.append(this.m_countPane, BorderLayout.EAST);
            var _local2:String = ZLoc.t("Items", (this.m_itemName + "_friendlyName"));
            m_message = ZLoc.t("Dialogs", "RemoveItemMessage", {
                numItem:this.m_itemCount,
                itemName:_local2
            });
            this.m_textAreaInnerPane.remove(this.m_textAP);
            this.m_textAP = this.createTextComponent(DIALOG_TEXT_WIDTH);
            this.m_textAreaInnerPane.append(this.m_textAP);
        }
        protected function decrementCount(_arg1:AWEvent):void{
            if (this.m_itemCount > 1){
                this.m_itemCount = (this.m_itemCount - 1);
            } else {
                if (this.m_itemCount == 1){
                    this.m_itemCount = Global.player.inventory.getItemCountByName(this.m_itemName);
                };
            };
            this.m_bottomPane.remove(this.m_countPane);
            this.m_countPane = this.makeCountPane();
            this.m_bottomPane.append(this.m_countPane, BorderLayout.EAST);
            var _local2:String = ZLoc.t("Items", (this.m_itemName + "_friendlyName"));
            m_message = ZLoc.t("Dialogs", "RemoveItemMessage", {
                numItem:this.m_itemCount,
                itemName:_local2
            });
            this.m_textAreaInnerPane.remove(this.m_textAP);
            this.m_textAP = this.createTextComponent(DIALOG_TEXT_WIDTH);
            this.m_textAreaInnerPane.append(this.m_textAP);
        }
        protected function createCell():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local2:DisplayObject = (new (m_assetDict["cell_bg"])() as DisplayObject);
            var _local3:DisplayObject = (new (m_assetDict["countBG"])() as DisplayObject);
            var _local4:DisplayObject = (new (m_assetDict["countMaxBG"])() as DisplayObject);
            var _local5:MarginBackground = new MarginBackground(_local2);
            _local1.setBackgroundDecorator(_local5);
            _local1.setPreferredSize(new IntDimension(_local2.width, _local2.height));
            _local1.setMinimumSize(new IntDimension(_local2.width, _local2.height));
            _local1.setMaximumSize(new IntDimension(_local2.width, _local2.height));
            var _local6:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.BOTTOM, -(OVERLAP_AMOUNT));
            var _local7:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local8:DisplayObject = m_assetDict["itemIcon"];
            var _local9:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local10:AssetPane = new AssetPane(_local8);
            var _local11:Number = ((_local2.width - _local8.width) / 2);
            _local9.append(ASwingHelper.horizontalStrut(_local11));
            _local9.append(_local10);
            _local7.append(_local9);
            _local1.append(_local7);
            _local6.append(_local1);
            this.m_countPane = this.makeCountPane();
            this.m_bottomPane = new JPanel(new BorderLayout());
            this.m_bottomPane.append(this.m_countPane, BorderLayout.EAST);
            _local6.append(this.m_bottomPane);
            ASwingHelper.prepare(_local6);
            return (_local6);
        }
        protected function makeCountPane():JPanel{
            var _local3:DisplayObject;
            var _local4:String;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local5:uint = 0xFFFFFF;
            if (this.m_itemCount >= Global.player.inventory.getItemCountByName(this.m_itemName)){
                _local3 = (new (InventoryView.assetDict["countMaxBG"])() as DisplayObject);
            } else {
                _local3 = (new (InventoryView.assetDict["countBG"])() as DisplayObject);
            };
            _local4 = String(this.m_itemCount);
            _local1.setBackgroundDecorator(new AssetBackground(_local3));
            _local1.setPreferredHeight(COUNT_PANE_SIZE);
            _local1.setMinimumHeight(COUNT_PANE_SIZE);
            _local1.setMaximumHeight(COUNT_PANE_SIZE);
            var _local6:JLabel = ASwingHelper.makeLabel(_local4, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 10, _local5);
            ASwingHelper.setEasyBorder(_local6, 0, 3, 0, 3);
            _local2.append(_local6);
            _local1.append(_local2);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        override protected function onAccept(_arg1:AWEvent):void{
            dispatchEvent(new RemoveItemEvent(GenericPopupEvent.SELECTED, YES, this.m_itemName, this.m_itemCount, true));
            if (m_closeCallback != null){
                removeEventListener(GenericPopupEvent.SELECTED, m_closeCallback);
            };
            closeMe();
        }

    }
}//package Display.InventoryUI 
